package com.wss.day02.test04;

/**
 * @author wangshaoshuai
 * @desc TODO
 * @date 2025/4/21
 */
public class Person {
    private String name;
    private int age;
    private boolean gender;
    private Person partner;

    public Person(String name, int age, boolean gender) {
        this.name = name;
        this.age = age;
        this.gender = gender;
    }


    public void marry(Person p) {

        if (this == p) {
            System.out.println(name + " 不能和自己结婚！");
            return;
        }


        if (this.gender == p.gender) {
            System.out.println(name + " 和 " + p.name + " 不能结婚：同性不能结婚！");
            return;
        }


        if ((this.gender && this.age < 24) || (!this.gender && this.age < 22)) {
            System.out.println(name + " 未达到法定结婚年龄！");
            return;
        }
        if ((p.gender && p.age < 24) || (!p.gender && p.age < 22)) {
            System.out.println(p.name + " 未达到法定结婚年龄！");
            return;
        }


        if (this.partner != null) {
            System.out.println(name + " 已经已婚，配偶是 " + this.partner.name);
            return;
        }
        if (p.partner != null) {
            System.out.println(p.name + " 已经已婚，配偶是 " + p.partner.name);
            return;
        }


        this.partner = p;
        p.partner = this;
        System.out.println("恭喜 " + this.name + " 和 " + p.name + " 喜结连理！");
    }


    public String getName() {
        return name;
    }

    public int getAge() {
        return age;
    }

    public boolean isGender() {
        return gender;
    }

    public Person getPartner() {
        return partner;
    }

    @Override
    public String toString() {
        return name + "(" + (gender ? "男" : "女") + ", " + age + "岁)";
    }
}
